using UnityEngine;
using System.Collections;

public class PaddleMove : MonoBehaviour {

	public int moveSpeed = 140;  //per second
	public bool isComputer = false;
	Vector3 computerDirection = Vector3.up;
	
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () 
	{
		if(!isComputer) PlayerMove();
		else ComputerMove();
	}
	
	void ComputerMove()
	{
		Vector3 newPosition = Vector3.zero;
		newPosition =  Vector3.up * Time.deltaTime * moveSpeed;
		transform.Translate(newPosition, Space.World);
		if(newPosition.y >= 70)
		{
			newPosition.y = 68;
			computerDirection.y *= -1;
		}
		else if(newPosition.y <= -70)
		{
			newPosition.y = -68;
			computerDirection.y *= -1;
		}
	}
	
	void PlayerMove()
	{
		Vector3 moveDirection = Vector3.zero;
		Vector3 newPosition = Vector3.zero;
		
		if(Input.GetKey(KeyCode.UpArrow)) moveDirection.y += 1;
		if(Input.GetKey(KeyCode.DownArrow)) moveDirection.y -= 1;
		
		moveDirection = moveDirection * (moveSpeed * Time.deltaTime);
		
		newPosition = transform.position + moveDirection;
		
		newPosition.y = Mathf.Clamp(newPosition.y, -82, 84);
		
		transform.position = newPosition;
	}
}
